package cn.clwxy.gdz.controller.presonalCenter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.clwxy.gdz.bo.PersonalCenterInfoBean;
import cn.clwxy.gdz.service.PersonalCenterInfoActService;
import cn.clwxy.gdz.service.PersonalCenterInfoActServiceImpl;
import cn.clwxy.gdz.util.JsonSerializeHelper;
import cn.clwxy.gdz.util.MD5Encrypter;

public class PersonalCenterChangePwdServlet extends HttpServlet {

	@Override
	public  void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("ok");
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		Integer teacherId =null;
		teacherId = Integer.valueOf(request.getParameter("teacherId"));
		String teacherOldPwd=request.getParameter("teacherOldPwd");
		String teacherNewPwd=request.getParameter("teacherNewPwd");
		String teacherPhone=request.getParameter("teacherPhone");
		
//		加密
		teacherOldPwd=MD5Encrypter.encrypt(teacherPhone+teacherOldPwd+teacherPhone);
		teacherNewPwd=MD5Encrypter.encrypt(teacherPhone+teacherNewPwd+teacherPhone);
		
		PersonalCenterInfoActService pcas = new PersonalCenterInfoActServiceImpl();
		if (pcas.getTeacherInfo(teacherId).getTeacherPwd().equals(teacherOldPwd)) {
		
		
		PersonalCenterInfoActService personalChangePwd = new PersonalCenterInfoActServiceImpl();
		int count=personalChangePwd.updatePwd(teacherId, teacherOldPwd, teacherNewPwd);
		System.out.println(count);
		Map results=new HashMap();
		results.put("a",count);
		response.setContentType("application/json");
		String result=JsonSerializeHelper.JsonSerializer(results);
		if(count==1){
			System.out.println("正确");
			response.getWriter().write("1");
		}else{
			System.out.println("错误");
			response.getWriter().write("0");
		}

		response.getWriter().flush();
		response.getWriter().close();
		

		}else{
			
			System.out.println("错误");
			response.getWriter().write("0");
		}
		

		 
		
//		super.service(request, response);
	}
	
}
